package com.Web_02;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet(name = "RequestDemo2", value = "/RequestDemo2")
public class RequestDemo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        获取请求头
        Enumeration<String> headerNames=request.getHeaderNames();

        while (headerNames.hasMoreElements()){
//            获取请求头
        String header=headerNames.nextElement();
//        根据请求头获取对应得值
            String value = request.getHeader(header);
            System.out.println(header+":"+value);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//          返回doget的方法
        this.doGet(request, response);

    }
}
